<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set locale information</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.rtrim.html">rtrim</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sha1-file.html">sha1_file</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.setlocale" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">setlocale</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">setlocale</span> &mdash; <span class="dc-title">Set locale information</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.setlocale-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>setlocale</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$category</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$...</code></span>
  ] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>setlocale</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$category</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$locale</code></span>
   )</div>

  <p class="para rdfs-comment">
   Sets locale information.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.setlocale-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">category</code></em></dt>

     <dd>

      <p class="para">
       <em><code class="parameter">category</code></em> is a named constant specifying the
       category of the functions affected by the locale setting:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <strong><code>LC_ALL</code></strong> for all of the below
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LC_COLLATE</code></strong> for string comparison, see
          <span class="function"><a href="function.strcoll.html" class="function">strcoll()</a></span>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LC_CTYPE</code></strong> for character classification and conversion, for
          example <span class="function"><a href="function.strtoupper.html" class="function">strtoupper()</a></span>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LC_MONETARY</code></strong> for <span class="function"><a href="function.localeconv.html" class="function">localeconv()</a></span>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LC_NUMERIC</code></strong> for decimal separator (See also
          <span class="function"><a href="function.localeconv.html" class="function">localeconv()</a></span>)
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LC_TIME</code></strong> for date and time formatting with
          <span class="function"><a href="function.strftime.html" class="function">strftime()</a></span>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LC_MESSAGES</code></strong> for system responses (available if PHP was compiled with
          <em>libintl</em>)
         </span>
        </li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">locale</code></em></dt>

     <dd>

      <p class="para">
       If <em><code class="parameter">locale</code></em> is <strong><code>NULL</code></strong> or the empty string
       <em>&quot;&quot;</em>, the locale names will be set from the
       values of environment variables with the same names as the above
       categories, or from &quot;LANG&quot;.
      </p>
      <p class="para">
       If <em><code class="parameter">locale</code></em> is <em>&quot;0&quot;</em>,
       the locale setting is not affected, only the current setting is returned.
      </p>
      <p class="para">
       If <em><code class="parameter">locale</code></em> is an array or followed by additional
       parameters then each array element or parameter is tried to be set as
       new locale until success. This is useful if a locale is known under
       different names on different systems or for providing a fallback
       for a possibly not available locale.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">...</code></em></dt>

     <dd>

      <p class="para">
       (Optional string or array parameters to try as locale settings until
       success.)
      </p>
     </dd>

    
   </dl>

   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
     On Windows, setlocale(LC_ALL, &#039;&#039;) sets the locale names from the
     system&#039;s regional/language settings (accessible via Control Panel).
    </p>
   </p></blockquote>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.setlocale-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the new current locale, or <strong><code>FALSE</code></strong> if the locale functionality is
   not implemented on your platform, the specified locale does not exist or
   the category name is invalid.
  </p>
  <p class="para">
   An invalid category name also causes a warning message. Category/locale
   names can be found in <a href="http://www.faqs.org/rfcs/rfc1766" class="link external">&raquo;&nbsp;RFC 1766</a>
   and <a href="http://www.w3.org/WAI/ER/IG/ert/iso639.htm" class="link external">&raquo;&nbsp;ISO 639</a>.
   Different systems have different naming schemes for locales.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The return value of <span class="function"><strong>setlocale()</strong></span> depends
    on the system that PHP is running.  It returns exactly
    what the system <em>setlocale</em> function returns.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.setlocale-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.0</td>
       <td>
        This function now throws an <strong><code>E_DEPRECATED</code></strong> notice if a string is passed 
        to the <em><code class="parameter">category</code></em> parameter instead of one of the 
        <em>LC_*</em> constants.
       </td>
      </tr>

      <tr>
       <td>4.3.0</td>
       <td>
        Passing multiple locales became possible.
       </td>
      </tr>

      <tr>
       <td>4.2.0</td>
       <td>
        Passing <em><code class="parameter">category</code></em> as a string is now deprecated,
        use the above constants instead.  Passing them as a string (within
        quotes) will result in a warning message.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.setlocale-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4760">
    <p><strong>Example #1 <span class="function"><strong>setlocale()</strong></span> Examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;locale&nbsp;to&nbsp;Dutch&nbsp;*/<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'nl_NL'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Output:&nbsp;vrijdag&nbsp;22&nbsp;december&nbsp;1978&nbsp;*/<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%A&nbsp;%e&nbsp;%B&nbsp;%Y"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">12</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">22</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1978</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;try&nbsp;different&nbsp;possible&nbsp;locale&nbsp;names&nbsp;for&nbsp;german&nbsp;as&nbsp;of&nbsp;PHP&nbsp;4.3.0&nbsp;*/<br /></span><span style="color: #0000BB">$loc_de&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de_DE@euro'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ge'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Preferred&nbsp;locale&nbsp;for&nbsp;german&nbsp;on&nbsp;this&nbsp;system&nbsp;is&nbsp;'</span><span style="color: #0000BB">$loc_de</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4761">
    <p><strong>Example #2 <span class="function"><strong>setlocale()</strong></span> Examples for Windows</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;locale&nbsp;to&nbsp;Dutch&nbsp;*/<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'nld_nld'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Output:&nbsp;vrijdag&nbsp;22&nbsp;december&nbsp;1978&nbsp;*/<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%A&nbsp;%d&nbsp;%B&nbsp;%Y"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">12</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">22</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1978</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;try&nbsp;different&nbsp;possible&nbsp;locale&nbsp;names&nbsp;for&nbsp;german&nbsp;as&nbsp;of&nbsp;PHP&nbsp;4.3.0&nbsp;*/<br /></span><span style="color: #0000BB">$loc_de&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de_DE@euro'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'deu_deu'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Preferred&nbsp;locale&nbsp;for&nbsp;german&nbsp;on&nbsp;this&nbsp;system&nbsp;is&nbsp;'</span><span style="color: #0000BB">$loc_de</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.setlocale-notes">
  <h3 class="title">注释</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    The locale information is maintained per process, not per thread. If you
    are running PHP on a multithreaded server API like IIS or Apache on
    Windows, you may experience sudden changes in locale settings while a
    script is running, though the script itself never called 
    <span class="function"><strong>setlocale()</strong></span>. This happens due to other scripts
    running in different threads of the same process at the same time,
    changing the process-wide locale using <span class="function"><strong>setlocale()</strong></span>.
   </p>
  </div>
  <div class="tip"><strong class="tip">Tip</strong>
   <p class="para">
    Windows users will find useful information about
    <em><code class="parameter">locale</code></em> strings at Microsoft&#039;s
    <acronym title="Microsoft Developer Network">MSDN</acronym> website. Supported language strings can be found
    in the
    <a href="http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.90%29.aspx" class="link external">&raquo;&nbsp;language strings documentation</a>
    and supported country/region strings in the
    <a href="http://msdn.microsoft.com/en-us/library/cdax410z%28v=vs.90%29.aspx" class="link external">&raquo;&nbsp;country/region strings documentation</a>.
   </p>
  </div>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.rtrim.html">rtrim</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sha1-file.html">sha1_file</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
